package com.example.s.view;

import android.annotation.SuppressLint;
import android.content.Context;
import android.util.Log;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;

import com.example.s.R;

public class MyWebView {
    private WebView webView;

    public MyWebView(WebView webView) {
        this.webView = webView;
        init();
    }

    @SuppressLint("WrongConstant")
    private void init() {
        webView.setScrollBarStyle(0);
        webView.getSettings().setDisplayZoomControls(false);
        webView.getSettings().setBuiltInZoomControls(true);
//       webView大比例的缩放
        webView.getSettings().setUseWideViewPort(true);
//       webView适应屏幕
        webView.getSettings().setLoadWithOverviewMode(true);
        webView.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN); //设置后可以拖动 不影响缩放
    }

    public MyWebView setDrawableSrc(Context context, int id) {
        String resourceName = context.getResources().getResourceEntryName(id);//改用picPath
        webView.loadUrl("file:///android_res/drawable/" + resourceName + ".png");  //url
        return this;
    }

    public MyWebView setNetWorkSrc(String src) {
        webView.loadUrl(src);  //url
        return this;
    }

    public WebView getWebView() {
        return webView;
    }
}
